package com.ztf.gui;


import com.ztf.bean.DataTransfer;
import com.ztf.bean.User;
import com.ztf.customer.Customer;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.FileInputStream;
import java.io.InputStream;

public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		Login frame = new Login();
		frame.setVisible(true);
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 350, 200);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("欢迎联系客服");
		lblNewLabel.setBounds(130, 21, 130, 16);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("账号");
		lblNewLabel_1.setBounds(50, 68, 40, 16);
		contentPane.add(lblNewLabel_1);

		textField = new JTextField();
		textField.setBounds(130, 63, 169, 26);
		contentPane.add(textField);
		textField.setColumns(10);

		//居中
		setLocationRelativeTo(null);

		JButton btnNewButton = new JButton("登录");
		btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String name = textField.getText();
				byte[] head =null;
				try {
					InputStream is = new FileInputStream("customerService/head/pic1.jpg");
					int len = is.available();
					head = new byte[len];
					is.read(head);
				} catch (Exception ee) {
					ee.printStackTrace();
				}

				Customer.send(new DataTransfer("login",new User(name,head,"客服",2)));
				ChatRoom.userNow = new User(name,head,"客服",3);
				ChatRoom.chatRoom = new ChatRoom();
				ChatRoom.chatRoom.setVisible(true);
				dispose();


			}
		});
		btnNewButton.setBounds(130, 100, 117, 29);
		contentPane.add(btnNewButton);

	}
}
